<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 商品咨询ajax类
 * @package  ajax
 * @subpackage  backend
 * @author   create by allen.qiang
 */

require 'module/base/contentHandler.class.php';

class ajax_goodsConsult {
	
	public function execute () {
		if (isset($_REQUEST['operFlg'])) {
			
			//获取参数标记
			$operFlg = $_REQUEST['operFlg'];
			
			switch ($operFlg) {
				case 1: //查询商品咨询
					$this->searchGoodsConsult();
					break;
				case 2: //删除商品咨询
					$this->deleteGoodsConsult();
					break;
				case 3: //商品咨询处理
					$this->dealGoodsConsult();
					break;
				case 4: //商品咨询导出
					$this->goodsConsultExport();
					break;
			}
		}
	}
	
	/**
	 * 获取商品咨询
	 * @author raohenglei
	 *
	 */
	private function searchGoodsConsult () {
		global $G_PGLOB;
		
		//实例化内容类
		$contentHandler = new contentHandler($G_PGLOB->DBCA);
		
		//查找商品咨询信息
		$goodsConsultList = $contentHandler->getGoodsConsultList( $_REQUEST );
		
		//组织返回的数据
        $result_array = array(
            'page' => $_REQUEST['page'],
            'total' => $_REQUEST['count'],
            'rows' => array()
        );
        
        if ($goodsConsultList) {
            foreach($goodsConsultList as &$consult) {
                $result_array['rows'][] = array(
                    'id' => $consult->uuid,
                    'cell' => array(
                        "<a href=\"javascript: void(0);\" onclick=\"goodsConsult.deal('".$consult->uuid."');\">处理</a>",
                        $consult->goodsName,
                        $consult->consultInfo,
                        $consult->createTime,
                        $consult->creator,
                        $consult->answerDateTime,
                        $consult->answerUserID,
                        $consult->consultStatus == 1 ? '已处理' : '未处理'
                    )
                );
            }
        }
		echo json_encode($result_array);
	}
	/**
	 * 删除商品咨询
	 * @author raohenglei
	 *
	 */
	private function deleteGoodsConsult () {
		global $G_PGLOB;
		
		//实例化内容类
		$contentHandler = new contentHandler( $G_PGLOB->DBCA );
		
		//删除选择的咨询
		$result_array = $contentHandler->deleteGoodsConsult( $_REQUEST );
		
		echo json_encode($result_array);
		
	}
	
	/**
	 * 处理商品咨询
	 * @author raohenglei
	 *
	 */
	private function dealGoodsConsult () {
		global $G_PGLOB;
		
		//实例化内容类
		$contentHandler = new contentHandler( $G_PGLOB->DBCA );
		
		$_REQUEST['answerUserID'] = $G_PGLOB->currentUserID;
		$_REQUEST['answerDateTime'] = $G_PGLOB->sys_datetime;
		
		$result_array = $contentHandler->dealGoodsConsult( $_REQUEST );
		
		echo json_encode( $result_array );
		
	}

}